<template>
	<view v-if="Object.keys(album).length > 0 || wallpaper.length > 0">
		<view class="album_bg">
			<image :src="album.cover" mode="widthFix"></image>
			<view class="album_info">
				<view class="album_name">{{album.name}}</view>
				<view class="album_btn">关注专辑</view>
			</view>
		</view>
			
		<view class="album_author">
			<view class="album_author_info">
				<image :src="album.user.avatar" mode="widthFix"></image>
				<view class="author_name">{{album.user.name}}</view>
			</view>
			<view class="album_author_desc">
				<text>{{album.desc}}</text>
			</view>
		</view>
		
		<view class="album_list">
			<view class="album_item"
			v-for="(item, index) in wallpaper"
			:key="item.id"
			>
				<goImgDetail :list="wallpaper" :index="index">
					<image :src="item.thumb + item.rule.replace('$<Height>', 360)" mode="aspectFill"></image>
				</goImgDetail>
				
			</view>
		</view>
		
	</view>
	
</template>

<script>
	import goImgDetail from '../../common/goImgDetail.vue'
	export default {
		components: {
			goImgDetail
		},
		data() {
			return {
				id: 0,
				
				params: {
					limit: 30,
					order: "new",
					skip: 0,
					first: 1
				},
				// 1 返回值中 有 album对象 表示第一次请求数据
				// 0 返回值中 只有 wallpaper 数组  不是第一次请求数据
				album: {},
				wallpaper: [],
				haveMore: true
			}
		},
		onLoad(e) {
			console.log(e)
			this.id = e.id;
			this.getAlbumList()
		},
		methods: {
			async getAlbumList() {
				const res = await this.$http({
					url: `/image/v1/wallpaper/album/${this.id}/wallpaper`,
					data: this.params
				})
				if(Object.keys(this.album).length == 0) {
					this.album = res.res.album;
				}
				if(res.res.wallpaper.length === 0) {
					this.haveMore = false;
					return
				}
				this.wallpaper = [...this.wallpaper, ...res.res.wallpaper];
			}
		},
		onReachBottom() {
			if(this.haveMore) {
				this.params.first = 0;
				this.params.skip += this.params.limit;
				this.getAlbumList()
			}else{
				uni.showToast({
					title: "没有更多数据了",
					icon: 'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.album_bg {
  position: relative;
  image {
  }

  .album_info {
    position: absolute;
    width: 100%;
    left: 0;
    bottom: 0;
    display: flex;
    justify-content: space-between;
    height: 80rpx;
    align-items: center;
    color: #fff;
    padding: 0 15rpx;
    .album_name {
      font-size: 40rpx;
    }

    .album_btn {
      background-color: $color;
      width: 152rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 10rpx;
    }
  }
}
.album_author {
  padding: 10rpx;
  .album_author_info {
    padding: 10rpx 0;
    display: flex;
    image {
      width: 50rpx;
    }

    .author_name {
      color: #000;
      margin-left: 15rpx;
    }
  }

  .album_author_desc {
  }
}
.album_list {
  display: flex;
  flex-wrap: wrap;
  .album_item {
    width: 33.33%;
    border: 3rpx solid #fff;
    image {
      height: 160rpx;
    }
  }
}
</style>
